
 <!DOCTYPE HTML>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  
    <title>Git全解析之用起来先 | wustrive&#39;s blog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=3, minimum-scale=1">
    
    <meta name="author" content="wustrive">
    
    <meta name="description" content="Git全解析之用起来先先安装Git环境下载安装：http://git-scm.com/download/
配置配置user与email,用来标识用户12$ git config --global user.name &quot;wustrive&quot;$ git config --global user.email">
    
    
    
    <meta name="twitter:card" content="summary" />
    <meta name="twitter:site" content="wustrive" />
    <meta name="twitter:title" content="Git全解析之用起来先 | wustrive&#39;s blog" />
      
    
    
    <link rel="alternate" href="/atom.xml" title="wustrive&#39;s blog" type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/logo.ico">
    <link rel="apple-touch-icon-precomposed" href="/img/logo.ico">
    
    <link rel="stylesheet" href="/css/style.css">
    <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?5829c94e2ff91660826b6c0c188f5620";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
    </script>

</head>

  <body>
    <header>
      <div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/logo.png" alt="wustrive&#39;s blog" title="wustrive&#39;s blog"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="wustrive&#39;s blog">wustrive&#39;s blog</a></h1>
				<h2 class="blog-motto">好记性不如写博客</h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="菜单">
			</a></div>
			<nav class="animated">
				<ul>
					
						<li><a href="/">主页</a></li>
					
						<li><a href="/archives">归档</a></li>
					
						<li><a href="/aboutme">关于</a></li>
					
					<li>
					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="text" id="search" name="q" autocomplete="off" maxlength="20" placeholder="搜索" />
						<input type="hidden" name="q" value="site:wustrive2008.github.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>

    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2016/01/06/版本控制/Git全解析之先用起来/" title="Git全解析之用起来先" itemprop="url">Git全解析之用起来先</a>
  </h1>
  <p class="article-author">By
    
      <a href="https://wustrive2008.github.io" title="wustrive">wustrive</a>
    </p>
  <p class="article-time">
    <time datetime="2016-01-06T14:23:16.000Z" itemprop="datePublished">2016-01-06</time>
    更新日期:<time datetime="2016-11-05T18:14:33.000Z" itemprop="dateModified">2016-11-06</time>
    
  </p>
</header>
	<div class="article-content">
		
<div class="article-gallery">
  <div class="article-gallery-photos">
    
      <a class="article-gallery-img fancybox" href="http://7xifb5.com1.z0.glb.clouddn.com/wustrive-hexogit%E7%9F%A5%E8%AF%86%E7%BB%93%E6%9E%84.png" rel="gallery_civ5jdlhx002tuvfyvf29s5be">
        <img src="http://7xifb5.com1.z0.glb.clouddn.com/wustrive-hexogit%E7%9F%A5%E8%AF%86%E7%BB%93%E6%9E%84.png" itemprop="image">
      </a>
    
  </div>
</div>

		
		<div id="toc" class="toc-article">
			<strong class="toc-title">文章目录</strong>
		<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Git全解析之用起来先"><span class="toc-number">1.</span> <span class="toc-text">Git全解析之用起来先</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#先安装Git环境"><span class="toc-number">1.1.</span> <span class="toc-text">先安装Git环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置"><span class="toc-number">1.2.</span> <span class="toc-text">配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#简单了解Git"><span class="toc-number">1.3.</span> <span class="toc-text">简单了解Git</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Git对象模型_SHA"><span class="toc-number">1.3.1.</span> <span class="toc-text">Git对象模型 SHA</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Git目录与工作目录"><span class="toc-number">1.3.2.</span> <span class="toc-text">Git目录与工作目录</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#可以开始使用了"><span class="toc-number">1.4.</span> <span class="toc-text">可以开始使用了</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#获取仓库"><span class="toc-number">1.4.1.</span> <span class="toc-text">获取仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#正常的工作流程"><span class="toc-number">1.4.2.</span> <span class="toc-text">正常的工作流程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#分支与合并"><span class="toc-number">1.4.3.</span> <span class="toc-text">分支与合并</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#基本操作命令"><span class="toc-number">1.4.3.1.</span> <span class="toc-text">基本操作命令</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#分支冲突"><span class="toc-number">1.4.3.2.</span> <span class="toc-text">分支冲突</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#撤销合并"><span class="toc-number">1.4.3.3.</span> <span class="toc-text">撤销合并</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#log记录"><span class="toc-number">1.4.4.</span> <span class="toc-text">log记录</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#比较差异DIFF"><span class="toc-number">1.4.5.</span> <span class="toc-text">比较差异DIFF</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#附录_-gitconfig文件配置参考"><span class="toc-number">1.5.</span> <span class="toc-text">附录 .gitconfig文件配置参考</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考"><span class="toc-number">1.6.</span> <span class="toc-text">参考</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#关于捐赠"><span class="toc-number">1.7.</span> <span class="toc-text">关于捐赠</span></a></li></ol></li></ol>
		</div>
		
		<h2 id="Git全解析之用起来先">Git全解析之用起来先</h2><h3 id="先安装Git环境">先安装Git环境</h3><p>下载安装：<a href="http://git-scm.com/download/" target="_blank" rel="external">http://git-scm.com/download/</a></p>
<h3 id="配置">配置</h3><p>配置user与email,用来标识用户<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ git config --global user.name <span class="string">"wustrive"</span></div><div class="line">$ git config --global user.email <span class="string">"wustrive2008@gmail.com"</span></div></pre></td></tr></table></figure></p>
<p>也可以直接编辑配置文件，配置文件默认路径在用户目录下的.gitconfig文件中，结构是：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[user]</div><div class="line">    name = wustrive</div><div class="line">    email = wustrive2008@gmail.com</div></pre></td></tr></table></figure></p>
<h3 id="简单了解Git">简单了解Git</h3><p>Git是一个快速的分布式版本控制系统</p>
<h4 id="Git对象模型_SHA">Git对象模型 SHA</h4><p>所有用来表示项目历史信息的文件是通过一个40个字符“对象名”来索引的。每一个“对象名”都是对“对象”内容做SHAI哈希计算来的。这个对象名是全局唯一的，不同的对象生成的“对象名”不同。</p>
<p>Git中四种类型的对象：”blob”,”tree”,”commit”和”tag”。每个对象包括三个部分：类型，大小和内容。</p>
<ul>
<li>blob用来存储文件数据</li>
<li>tree有点像一个目录，用来管理一些blob与tree</li>
<li>commit，一个commit只指向一个tree，用来标记项目某一个特定时间点的状态，即一次提交</li>
<li>tag，一个tag用来标记一个commit</li>
</ul>
<h4 id="Git目录与工作目录">Git目录与工作目录</h4><p>git目录是为你的项目存储所有历史和元信息的目录，包括所有对象，这些对象指向不同的分支，每个项目只能有一个Git目录,这个叫’.git’的目录一般在项目的根目录下，<br>这个目录下的重要文件有：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">.</div><div class="line">|-- FETCH_HEAD <span class="comment">#指向着目前已经从远程仓库取下来的分支的末端版本。</span></div><div class="line">|-- HEAD <span class="comment">#这个git项目当前处在哪个分支里</span></div><div class="line">|-- ORIG_HEAD <span class="comment">#HEAD指针的前一个状态</span></div><div class="line">|-- branches/ <span class="comment">#项目的所有分支</span></div><div class="line">|-- config/ <span class="comment">#项目的配置信息，git config命令会改动它</span></div><div class="line">|-- description <span class="comment">#项目的描述信息</span></div><div class="line">|-- hooks/ <span class="comment">#系统默认钩子脚本目录</span></div><div class="line">|-- index <span class="comment">#索引文件</span></div><div class="line">|-- info/ <span class="comment">#包含仓库的一些信息</span></div><div class="line">|-- logs/ <span class="comment">#各个refs的历史信息</span></div><div class="line">|-- objects/ <span class="comment">#Git本地仓库的所有对象 (commits, trees, blobs, tags)</span></div><div class="line">|-- packed-refs <span class="comment">#运行 git gc, refs 下的所有文件都会消失。Git 会将这些文件挪到 .git/packed-refs 文件中去以提高效率</span></div><div class="line">|-- refs/ <span class="comment">#标识你项目里的每个分支指向了哪个提交(commit)</span></div></pre></td></tr></table></figure></p>
<p>工作目录就是你的项目源代码目录，即是你签出(checkout)用来编辑的文件，当在不同的分支间切换时，工作目录里的内容会随之替换或删除，所有的操作历史都保存在Git目录中，工作目录是用来临时保存checkout文件的地方。</p>
<h3 id="可以开始使用了">可以开始使用了</h3><h4 id="获取仓库">获取仓库</h4><ul>
<li><p>创建仓库，在工作目录下执行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git init .</div></pre></td></tr></table></figure>
</li>
<li><p>clone一个仓库</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#通过http(s)协议</span></div><div class="line">git <span class="built_in">clone</span> https://github.com/git/git.git</div><div class="line"><span class="comment">#通过ssh协议</span></div><div class="line">git <span class="built_in">clone</span> git@github.com:git/git.git</div></pre></td></tr></table></figure>
</li>
</ul>
<p><strong>提示：创建和clone后默认的分支是master，默认的repository引用名称origin</strong></p>
<h4 id="正常的工作流程">正常的工作流程</h4><ol>
<li><p>修改文件，将它们更新的内容添加到索引中</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">git add file1 file2 file3</div><div class="line"><span class="comment">#也可以通过git add . 来添加所有变动到暂存区</span></div><div class="line">git add .</div></pre></td></tr></table></figure>
</li>
<li><p>查看当状态</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">$ git status</div><div class="line"><span class="comment"># On branch master</span></div><div class="line"><span class="comment"># Changes to be committed:</span></div><div class="line"><span class="comment"># (use "git reset HEAD &lt;file&gt;..." to unstage)</span></div><div class="line"><span class="comment">#</span></div><div class="line"><span class="comment"># modified: file1</span></div><div class="line"><span class="comment"># modified: file2</span></div><div class="line"><span class="comment"># modified: file3</span></div><div class="line"><span class="comment">#</span></div></pre></td></tr></table></figure>
</li>
<li><p>提交commit</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#执行后会进入编辑器进行注释编辑</span></div><div class="line">$ git commit</div><div class="line"></div><div class="line"><span class="comment">#如果注释很短也可以使用</span></div><div class="line">$ git commit -m <span class="string">"注释内容"</span></div><div class="line"></div><div class="line"><span class="comment">#如果只是修改了文件，没有添加新的文件，可以省略git add</span></div><div class="line">$ git commit -am <span class="string">"注释内容"</span></div></pre></td></tr></table></figure>
</li>
</ol>
<h4 id="分支与合并">分支与合并</h4><h5 id="基本操作命令">基本操作命令</h5><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#查看本地分支 *代表当前所在分支</span></div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">* master</div><div class="line"></div><div class="line"><span class="comment">#新建分支</span></div><div class="line">[centos@bogon gittest]$ git branch br1</div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">  br1</div><div class="line">* master</div><div class="line"></div><div class="line"><span class="comment">#切换分支</span></div><div class="line">[centos@bogon gittest]$ git checkout br1</div><div class="line">Switched to branch <span class="string">'br1'</span></div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">* br1</div><div class="line">  master</div><div class="line"></div><div class="line"><span class="comment">#切换并合并分支，以当前分支为基础新建分支</span></div><div class="line">[centos@bogon gittest]$ ll</div><div class="line">total 0</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file1</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file2</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file3</div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">* br1</div><div class="line">  master</div><div class="line">[centos@bogon gittest]$ git checkout -b br2</div><div class="line">Switched to a new branch <span class="string">'br2'</span></div><div class="line">[centos@bogon gittest]$ ll</div><div class="line">total 0</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file1</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file2</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file3</div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">  br1</div><div class="line">* br2</div><div class="line">  master</div><div class="line"></div><div class="line"><span class="comment">#合并分支，将其他分支合并到当前分支</span></div><div class="line">[centos@bogon gittest]$ ll</div><div class="line">total 0</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file1</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file2</div><div class="line">-rw-rw-r--. 1 centos centos 0 Jan  6 23:32 file3</div><div class="line">[centos@bogon gittest]$ git merge br2</div><div class="line">Updating da5068b..f9da174</div><div class="line">Fast-forward</div><div class="line"> br2-file |    1 +</div><div class="line"> 1 files changed, 1 insertions(+), 0 deletions(-)</div><div class="line"> create mode 100644 br2-file</div><div class="line">[centos@bogon gittest]$ ll</div><div class="line">total 4</div><div class="line">-rw-rw-r--. 1 centos centos 10 Jan  6 23:44 br2-file</div><div class="line">-rw-rw-r--. 1 centos centos  0 Jan  6 23:32 file1</div><div class="line">-rw-rw-r--. 1 centos centos  0 Jan  6 23:32 file2</div><div class="line">-rw-rw-r--. 1 centos centos  0 Jan  6 23:32 file3   </div><div class="line"></div><div class="line"><span class="comment">#删除分支，删除已经被合并过的分支，安全删除分支</span></div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">  br1</div><div class="line">  br2</div><div class="line">* master</div><div class="line">[centos@bogon gittest]$ git branch <span class="_">-d</span> br2</div><div class="line">Deleted branch br2 (was f9da174).</div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">  br1</div><div class="line">* master</div><div class="line"></div><div class="line"><span class="comment">#强制删除分支</span></div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">  br1</div><div class="line">* master</div><div class="line">[centos@bogon gittest]$ git branch -D br1</div><div class="line">Deleted branch br1 (was da5068b).</div><div class="line">[centos@bogon gittest]$ git branch</div><div class="line">* master</div></pre></td></tr></table></figure>
<h5 id="分支冲突">分支冲突</h5><p>如果执行自动合并没有成功的话，git会在索引和工作树里设置一个特殊的状态， 提示你如何解决合并中出现的冲突。<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">[centos@bogon gittest]$ git merge br1</div><div class="line">Auto-merging file1</div><div class="line">CONFLICT (content): Merge conflict <span class="keyword">in</span> file1</div><div class="line">Automatic merge failed; fix conflicts and <span class="keyword">then</span> commit the result.</div><div class="line">[centos@bogon gittest]$ git status</div><div class="line"><span class="comment"># On branch master</span></div><div class="line"><span class="comment"># Unmerged paths:</span></div><div class="line"><span class="comment">#   (use "git add/rm &lt;file&gt;..." as appropriate to mark resolution)</span></div><div class="line"><span class="comment">#</span></div><div class="line"><span class="comment">#   both modified:      file1</span></div><div class="line"><span class="comment">#</span></div><div class="line">no changes added to commit (use <span class="string">"git add"</span> and/or <span class="string">"git commit -a"</span>)</div></pre></td></tr></table></figure></p>
<p>有冲突(conflicts)的文件会保存在索引中，在commit之前要解决冲突，解决冲突的方式就是编辑冲突文件，重新commit。</p>
<h5 id="撤销合并">撤销合并</h5><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#如果合并分支后又后悔了，可以撤销合并</span></div><div class="line">[centos@bogon gittest]$ git reset --hard HEAD</div><div class="line">HEAD is now at 2fa716d file1 master</div><div class="line">[centos@bogon gittest]$ git status</div><div class="line"><span class="comment"># On branch master</span></div><div class="line">nothing to commit (working directory clean)</div><div class="line"></div><div class="line"><span class="comment">#如果已经把合并后的代码提交了，可以执行</span></div><div class="line">[centos@bogon gittest]$ git reset --hard ORIG_HEAD</div><div class="line">HEAD is now at 2fa716d file1 master</div></pre></td></tr></table></figure>
<h4 id="log记录">log记录</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">$ git <span class="built_in">log</span> v2.5.. <span class="comment"># commits since (not reachable from) v2.5</span></div><div class="line">$ git <span class="built_in">log</span> test..master <span class="comment"># commits reachable from master but not test</span></div><div class="line">$ git <span class="built_in">log</span> master..test <span class="comment"># commits reachable from test but not master</span></div><div class="line">$ git <span class="built_in">log</span> master...test <span class="comment"># commits reachable from either test or</span></div><div class="line"><span class="comment"># master, but not both</span></div><div class="line">$ git <span class="built_in">log</span> --since=<span class="string">"2 weeks ago"</span> <span class="comment"># commits from the last 2 weeks</span></div><div class="line">$ git <span class="built_in">log</span> Makefile <span class="comment"># commits that modify Makefile</span></div><div class="line">$ git <span class="built_in">log</span> fs/ <span class="comment"># commits that modify any file under fs/</span></div><div class="line">$ git <span class="built_in">log</span> -S<span class="string">'foo()\'</span> <span class="comment"># commits that add or remove any file data</span></div><div class="line"><span class="comment"># matching the string 'foo()'</span></div><div class="line">$ git <span class="built_in">log</span> --no-merges <span class="comment"># dont show merge commits</span></div></pre></td></tr></table></figure>
<p>示例：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div></pre></td><td class="code"><pre><div class="line">#查看当前分支log</div><div class="line">[centos@bogon gittest]$ git log</div><div class="line">commit 2fa716df1d841ac2347cd9b6d371cfdf71682dfe</div><div class="line">Author: wubaoguo &lt;wustrive_2008@126.com&gt;</div><div class="line">Date:   Wed Jan 6 23:53:20 2016 +0800</div><div class="line"></div><div class="line">    file1 master</div><div class="line"></div><div class="line">commit f9da1748bddb6cfcc0f492f60328abcd54f97663</div><div class="line">Author: wubaoguo &lt;wustrive_2008@126.com&gt;</div><div class="line">Date:   Wed Jan 6 23:44:08 2016 +0800</div><div class="line"></div><div class="line">    br2</div><div class="line"></div><div class="line">commit da5068b35246dc26b77105a6dc6c2aa6e430fcad</div><div class="line">Author: wubaoguo &lt;wustrive_2008@126.com&gt;</div><div class="line">Date:   Wed Jan 6 23:38:39 2016 +0800</div><div class="line"></div><div class="line">    init</div><div class="line"></div><div class="line">#查看详细变动</div><div class="line">[centos@bogon gittest]$ git log --stat</div><div class="line">commit 2fa716df1d841ac2347cd9b6d371cfdf71682dfe</div><div class="line">Author: wubaoguo &lt;wustrive_2008@126.com&gt;</div><div class="line">Date:   Wed Jan 6 23:53:20 2016 +0800</div><div class="line"></div><div class="line">    file1 master</div><div class="line"></div><div class="line"> file1 |    1 +</div><div class="line"> 1 files changed, 1 insertions(+), 0 deletions(-)</div><div class="line"></div><div class="line">commit f9da1748bddb6cfcc0f492f60328abcd54f97663</div><div class="line">Author: wubaoguo &lt;wustrive_2008@126.com&gt;</div><div class="line">Date:   Wed Jan 6 23:44:08 2016 +0800</div><div class="line"></div><div class="line">    br2</div><div class="line"></div><div class="line"> br2-file |    1 +</div><div class="line"> 1 files changed, 1 insertions(+), 0 deletions(-)</div><div class="line"></div><div class="line">commit da5068b35246dc26b77105a6dc6c2aa6e430fcad</div><div class="line">Author: wubaoguo &lt;wustrive_2008@126.com&gt;</div><div class="line">Date:   Wed Jan 6 23:38:39 2016 +0800</div><div class="line"></div><div class="line">    init</div><div class="line"></div><div class="line"></div><div class="line">#格式化log输出结果</div><div class="line">[centos@bogon gittest]$ git log --pretty=oneline</div><div class="line">2fa716df1d841ac2347cd9b6d371cfdf71682dfe file1 master</div><div class="line">f9da1748bddb6cfcc0f492f60328abcd54f97663 br2</div><div class="line">da5068b35246dc26b77105a6dc6c2aa6e430fcad init</div><div class="line"></div><div class="line">#更友好的格式化，历史多了效果明显</div><div class="line">[centos@bogon gittest]$ git log --pretty=format:&apos;%h : %s&apos; --graph</div><div class="line">* 2fa716d : file1 master</div><div class="line">* f9da174 : br2</div><div class="line">* da5068b : init</div></pre></td></tr></table></figure></p>
<h4 id="比较差异DIFF">比较差异DIFF</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#比较分支间的差异</span></div><div class="line">[centos@bogon gittest]$ git diff master..br1</div><div class="line">diff --git a/file1 b/file1</div><div class="line">index 3325d54..76e65f5 100644</div><div class="line">--- a/file1</div><div class="line">+++ b/file1</div><div class="line">@@ -1 +1 @@</div><div class="line">-file1 master</div><div class="line">+file1 br1</div><div class="line"></div><div class="line"><span class="comment">#工作目录与暂存区(staged)差异</span></div><div class="line">[centos@bogon gittest]$ git diff</div><div class="line">diff --git a/file2 b/file2</div><div class="line">index e69de29..35d5537 100644</div><div class="line">--- a/file2</div><div class="line">+++ b/file2</div><div class="line">@@ -0,0 +1,2 @@</div><div class="line">+diff 的使用</div><div class="line">+</div><div class="line"></div><div class="line"><span class="comment">#暂存区与上次提交之间的差异</span></div><div class="line">[centos@bogon gittest]$ git add .</div><div class="line">[centos@bogon gittest]$ git diff --cached</div><div class="line">diff --git a/file2 b/file2</div><div class="line">index e69de29..35d5537 100644</div><div class="line">--- a/file2</div><div class="line">+++ b/file2</div><div class="line">@@ -0,0 +1,2 @@</div><div class="line">+diff 的使用</div><div class="line">+</div><div class="line"></div><div class="line"><span class="comment">#工作目录与上次提交之间的差异</span></div><div class="line">[centos@bogon gittest]$ git diff HEAD</div><div class="line">diff --git a/file2 b/file2</div><div class="line">index e69de29..35d5537 100644</div><div class="line">--- a/file2</div><div class="line">+++ b/file2</div><div class="line">@@ -0,0 +1,2 @@</div><div class="line">+diff 的使用</div><div class="line">+</div><div class="line">diff --git a/file3 b/file3</div><div class="line">index e69de29..1bf6afb 100644</div><div class="line">--- a/file3</div><div class="line">+++ b/file3</div><div class="line">@@ -0,0 +1 @@</div><div class="line">+还没commit  工作目录又改动了</div></pre></td></tr></table></figure>
<h3 id="附录_-gitconfig文件配置参考">附录 .gitconfig文件配置参考</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div></pre></td><td class="code"><pre><div class="line">[user]</div><div class="line">    name = zhangsan</div><div class="line">    email = zhangsan@gmail.com</div><div class="line">[color]</div><div class="line">    branch = auto</div><div class="line">    diff = auto</div><div class="line">    status = auto</div><div class="line">    ui = auto</div><div class="line"></div><div class="line">[core]</div><div class="line">    quotepath=<span class="literal">false</span></div><div class="line">    edit = vim</div><div class="line">    autocrlf = <span class="literal">true</span></div><div class="line">    filemode = <span class="literal">false</span></div><div class="line">[i18n]</div><div class="line">    commitencoding = UTF-8</div><div class="line">[gui]</div><div class="line">    encoding = utf-8</div><div class="line">[<span class="built_in">alias</span>]</div><div class="line">    stage = add</div><div class="line">    unstage = reset HEAD</div><div class="line">    hb = merge --no-ff</div><div class="line">    rmv = remote -v</div><div class="line">    ci = commit</div><div class="line">    cia = commit --amend</div><div class="line">    co = checkout</div><div class="line">    br = branch</div><div class="line">    st = status</div><div class="line">    dc = diff --cached</div><div class="line">    dw = diff --word-diff</div><div class="line">    aa = add -A</div><div class="line">    rmall = !git ls-files --deleted | xargs git rm</div><div class="line">    ll = <span class="built_in">log</span> --pretty=format:<span class="string">"%C(yellow)%h%Cred%d%Creset\\ %cn\\ %Cblue%cr%Creset\\ %Cgreen%s%Creset"</span> --decorate --numstat</div><div class="line">    lg = <span class="built_in">log</span> --pretty=format:<span class="string">"%C(yellow)%h%Cred%d%Creset\\ %cn\\ %Cblue%cr%Creset\\ %Cgreen%s%Creset"</span> --decorate</div><div class="line">    lt = <span class="built_in">log</span> --pretty=format:<span class="string">"%C(yellow)%h%Cred%d%Creset\\ %cn\\ %Cblue%cr%Creset\\ %Cgreen%s%Creset"</span> --graph</div><div class="line">[receive]</div><div class="line">    denyCurrentBranch = ignore</div></pre></td></tr></table></figure>
<p>更多配置文件参考: <a href="https://github.com/wustrive2008/conf-file" target="_blank" rel="external">https://github.com/wustrive2008/conf-file</a></p>
<h3 id="参考">参考</h3><p>《Git Community Book》</p>
<h3 id="关于捐赠">关于捐赠</h3><p>如何觉得本文章对你有帮助，欢迎通过支付宝捐赠来支持博主</p>
<p><img src="http://7xifb5.com1.z0.glb.clouddn.com/wustrive-hexo%E6%94%AF%E4%BB%98%E5%AE%9D%E4%BB%98%E6%AC%BE%E4%BA%8C%E7%BB%B4%E7%A0%81%E6%9C%80%E5%B0%8F.png" alt="捐赠"></p>
  
	</div>
		<footer class="article-footer clearfix">

  <div class="article-tags">
  
  <span></span> <a href="/tags/git/">git</a><a href="/tags/版本控制/">版本控制</a><a href="/tags/项目管理/">项目管理</a>
  </div>


<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/categories/版本控制/">版本控制</a>
</div>



<div class="article-share" id="share">

  <div data-url="https://wustrive2008.github.io/2016/01/06/版本控制/Git全解析之先用起来/" data-title="Git全解析之用起来先 | wustrive&#39;s blog" data-tsina="null" class="share clearfix">
  </div>

</div>
</footer>   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2016/01/08/python/python闭包与装饰器/" title="python闭包与装饰器">
  <strong>PREVIOUS:</strong><br/>
  <span>
  python闭包与装饰器</span>
</a>
</div>


<div class="next">
<a href="/2016/01/05/python/python基础语法/"  title="python基础语法">
 <strong>NEXT:</strong><br/> 
 <span>python基础语法
</span>
</a>
</div>

</nav>

	
<section class="comment">
	<div class="ds-thread"></div>
</section>

</div>  
      <div class="openaside"><a class="navbutton" href="#" title="显示侧边栏"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">文章目录</strong>
  <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Git全解析之用起来先"><span class="toc-number">1.</span> <span class="toc-text">Git全解析之用起来先</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#先安装Git环境"><span class="toc-number">1.1.</span> <span class="toc-text">先安装Git环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置"><span class="toc-number">1.2.</span> <span class="toc-text">配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#简单了解Git"><span class="toc-number">1.3.</span> <span class="toc-text">简单了解Git</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Git对象模型_SHA"><span class="toc-number">1.3.1.</span> <span class="toc-text">Git对象模型 SHA</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Git目录与工作目录"><span class="toc-number">1.3.2.</span> <span class="toc-text">Git目录与工作目录</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#可以开始使用了"><span class="toc-number">1.4.</span> <span class="toc-text">可以开始使用了</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#获取仓库"><span class="toc-number">1.4.1.</span> <span class="toc-text">获取仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#正常的工作流程"><span class="toc-number">1.4.2.</span> <span class="toc-text">正常的工作流程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#分支与合并"><span class="toc-number">1.4.3.</span> <span class="toc-text">分支与合并</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#基本操作命令"><span class="toc-number">1.4.3.1.</span> <span class="toc-text">基本操作命令</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#分支冲突"><span class="toc-number">1.4.3.2.</span> <span class="toc-text">分支冲突</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#撤销合并"><span class="toc-number">1.4.3.3.</span> <span class="toc-text">撤销合并</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#log记录"><span class="toc-number">1.4.4.</span> <span class="toc-text">log记录</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#比较差异DIFF"><span class="toc-number">1.4.5.</span> <span class="toc-text">比较差异DIFF</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#附录_-gitconfig文件配置参考"><span class="toc-number">1.5.</span> <span class="toc-text">附录 .gitconfig文件配置参考</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考"><span class="toc-number">1.6.</span> <span class="toc-text">参考</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#关于捐赠"><span class="toc-number">1.7.</span> <span class="toc-text">关于捐赠</span></a></li></ol></li></ol>
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="隐藏侧边栏"></a></div>
<aside class="clearfix">

  
<div class="categorieslist">
	<p class="asidetitle">分类</p>
		<ul>
		
			<li><a href="/categories/DB/" title="DB">DB<sup>1</sup></a></li>
		
			<li><a href="/categories/Linux/" title="Linux">Linux<sup>6</sup></a></li>
		
			<li><a href="/categories/UML/" title="UML">UML<sup>1</sup></a></li>
		
			<li><a href="/categories/cORc/" title="cORc++">cORc++<sup>1</sup></a></li>
		
			<li><a href="/categories/hexo/" title="hexo">hexo<sup>1</sup></a></li>
		
			<li><a href="/categories/http协议/" title="http协议">http协议<sup>2</sup></a></li>
		
			<li><a href="/categories/java/" title="java">java<sup>10</sup></a></li>
		
			<li><a href="/categories/js/" title="js">js<sup>1</sup></a></li>
		
			<li><a href="/categories/nginx/" title="nginx">nginx<sup>1</sup></a></li>
		
			<li><a href="/categories/python/" title="python">python<sup>2</sup></a></li>
		
			<li><a href="/categories/分享/" title="分享">分享<sup>1</sup></a></li>
		
			<li><a href="/categories/摘录/" title="摘录">摘录<sup>1</sup></a></li>
		
			<li><a href="/categories/版本控制/" title="版本控制">版本控制<sup>3</sup></a></li>
		
			<li><a href="/categories/算法/" title="算法">算法<sup>2</sup></a></li>
		
			<li><a href="/categories/缓存/" title="缓存">缓存<sup>1</sup></a></li>
		
			<li><a href="/categories/网络协议/" title="网络协议">网络协议<sup>1</sup></a></li>
		
			<li><a href="/categories/网络安全/" title="网络安全">网络安全<sup>1</sup></a></li>
		
			<li><a href="/categories/设计模式/" title="设计模式">设计模式<sup>2</sup></a></li>
		
			<li><a href="/categories/读书笔记/" title="读书笔记">读书笔记<sup>10</sup></a></li>
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">标签</p>
		<ul class="clearfix">
		
			<li><a href="/tags/Arraylist/" title="Arraylist">Arraylist<sup>1</sup></a></li>
		
			<li><a href="/tags/Centos/" title="Centos">Centos<sup>2</sup></a></li>
		
			<li><a href="/tags/DB/" title="DB">DB<sup>1</sup></a></li>
		
			<li><a href="/tags/Docker/" title="Docker">Docker<sup>1</sup></a></li>
		
			<li><a href="/tags/Email/" title="Email">Email<sup>1</sup></a></li>
		
			<li><a href="/tags/HashMap/" title="HashMap">HashMap<sup>1</sup></a></li>
		
			<li><a href="/tags/HotSpot/" title="HotSpot">HotSpot<sup>1</sup></a></li>
		
			<li><a href="/tags/IMAP/" title="IMAP">IMAP<sup>1</sup></a></li>
		
			<li><a href="/tags/Java/" title="Java">Java<sup>1</sup></a></li>
		
			<li><a href="/tags/Linux/" title="Linux">Linux<sup>5</sup></a></li>
		
			<li><a href="/tags/OOM/" title="OOM">OOM<sup>1</sup></a></li>
		
			<li><a href="/tags/POP3/" title="POP3">POP3<sup>1</sup></a></li>
		
			<li><a href="/tags/SMTP/" title="SMTP">SMTP<sup>1</sup></a></li>
		
			<li><a href="/tags/Tomcat/" title="Tomcat">Tomcat<sup>1</sup></a></li>
		
			<li><a href="/tags/UML/" title="UML">UML<sup>1</sup></a></li>
		
			<li><a href="/tags/aes/" title="aes">aes<sup>1</sup></a></li>
		
			<li><a href="/tags/array/" title="array">array<sup>1</sup></a></li>
		
			<li><a href="/tags/arraylist/" title="arraylist">arraylist<sup>1</sup></a></li>
		
			<li><a href="/tags/c/" title="c">c<sup>2</sup></a></li>
		
			<li><a href="/tags/chkconfig/" title="chkconfig">chkconfig<sup>1</sup></a></li>
		
		</ul>
</div>


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS 订阅</a>
</div>

</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello, I&#39;m wustrive. This is my blog on GitHub. <br/>
			I wish you happiness</p>
	</section>
	 
	<div class="social-font clearfix">
		
		<a href="http://weibo.com/12100106" target="_blank" title="weibo"></a>
		
		
		<a href="https://twitter.com/wustrive" target="_blank" title="twitter"></a>
		
		
		<a href="https://github.com/wustrive2008" target="_blank" title="github"></a>
		
		
		
	</div>
		<p class="copyright">Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/A-limon/pacman" target="_blank" title="Pacman">Pacman</a> © 2018 
		
		<a href="https://wustrive2008.github.io" target="_blank" title="wustrive">wustrive</a>
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else
    {
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      h  = $('article h2')
      ah = $('article h2'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  if(ah.length==0){
    t.css('display','none');
  }else{
    c.click(function(){
      ta.css('display', 'block').addClass('fadeIn');
    });
    o.click(function(){
      ta.css('display', 'none');
    });
    $(window).scroll(function(){
      ta.css("top",Math.max(140,320-$(this).scrollTop()));
    });
  };
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina');
  var html = [
  '<a href="#" class="overlay" id="qrcode"></a>',
  '<div class="qrcode clearfix"><span>扫描二维码分享到微信朋友圈</span><a class="qrclose" href="#share"></a><strong>Loading...Please wait</strong><img id="qrcode-pic" data-src="http://s.jiathis.com/qrcode.php?url=' + encodedUrl + '"/></div>',
  '<a href="#textlogo" class="article-back-to-top" title="Top"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="QRcode"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="Weibo"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);
  $('.article-share-qrcode').click(function(){
    var imgSrc = $('#qrcode-pic').attr('data-src');
    $('#qrcode-pic').attr('src', imgSrc);
    $('#qrcode-pic').load(function(){
        $('.qrcode strong').text(' ');
    });
  });
});     
</script>


<script type="text/javascript">
  var duoshuoQuery = {short_name:"wustrive"};
  (function() {
    var ds = document.createElement('script');
    ds.type = 'text/javascript';ds.async = true;
    ds.src = '//static.duoshuo.com/embed.js';
    ds.charset = 'UTF-8';
    (document.getElementsByTagName('head')[0] 
    || document.getElementsByTagName('body')[0]).appendChild(ds);
  })();
</script> 




<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-22190106-2', 'auto');  
ga('send', 'pageview');
</script>


<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-22190106-2', 'auto');
  ga('send', 'pageview');

</script>

  </body>
</html>
